import axios from 'axios';

const service = axios.create({
  timeout: 15000 // 请求超时时间
})
// 拦截器
// request拦截器
service.interceptors.request.use(config => {

  return config
}, error => {
  console.log(error) // for debug
  Promise.reject(error)
})

// respone拦截器
service.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    console.log('err:' + error) // for debug
    return Promise.reject(error)
  }
)

export const post = function (url, data) {
  return service.post(url, data, {
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

export const get = function (url, params) {
  return service.get(url, { params });
}

export default axios;